package www.openteam.com.adapter.policy;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.SendRcvPoductMsg;

public class SendRcvApprlChildAdp extends RecyclerView.Adapter<SendRcvApprlChildAdp.ViewHolder> {

    Context context;
    List<SendRcvPoductMsg.DataBeanX.DataBean> dataBeans = new ArrayList<>();
    SendRcvAlChildAdpClick sendRcvAlChildAdpClick;
    List<Boolean> isflag = new ArrayList<>();


    public SendRcvApprlChildAdp(Context context, List<SendRcvPoductMsg.DataBeanX.DataBean> dataBeans) {
        this.context = context;
        this.dataBeans = dataBeans;
    }

    public SendRcvApprlChildAdp(Context context) {
        this.context = context;
    }

    public void setDataBeans(List<SendRcvPoductMsg.DataBeanX.DataBean> dataBeans) {
        this.dataBeans = dataBeans;
    }

    interface SendRcvAlChildAdpClick {
        void postdata();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_sendrcv_apprl_child, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        SendRcvPoductMsg.DataBeanX.DataBean dataBean = dataBeans.get(i);
        viewHolder.srcvApprlChildDate.setText(i+"");
        viewHolder.srcvApprlChildProcno.setText(dataBean.getProcno());
        viewHolder.srcvApprlChildCode.setText(dataBean.getCode());
        viewHolder.srcvApprlChildName.setText(dataBean.getName());
        viewHolder.srckApprlChildPartId.setText(dataBean.getPartID());
        viewHolder.srckApprlChildGroupName.setText(dataBean.getGroupname());
//        viewHolder.srckApprlChildApprlprocId.setText(dataBean.getProcID()+"");
        viewHolder.srckApprlChildApprlChildprocName.setText(dataBean.getProcName());
        viewHolder.srckApprlChildAmount.setText(cleanDecimal(dataBean.getAllsum()));
        viewHolder.srckApprlChildGoodNum.setText(cleanDecimal(dataBean.getReqGoodNumb()));
        viewHolder.srckApprlChildPjctReq.setText(dataBean.getOtReason());
        viewHolder.srckApprlChildOtherState.setText(dataBean.getOtherNote());

    }

    public String cleanDecimal(String text){
        Double num = Double.valueOf(text.isEmpty() ? "0" : text);
        NumberFormat nf = NumberFormat.getInstance();
        return nf.format(num);
    }

    @Override
    public int getItemCount() {
        return dataBeans.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.srcv_apprl_child_date)
        TextView srcvApprlChildDate;
        @Bind(R.id.srcv_apprl_child_procno)
        TextView srcvApprlChildProcno;
        @Bind(R.id.srcv_apprl_child_code)
        TextView srcvApprlChildCode;
        @Bind(R.id.srcv_apprl_child_name)
        TextView srcvApprlChildName;
        @Bind(R.id.srck_apprl_child_partId)
        TextView srckApprlChildPartId;
        @Bind(R.id.srck_apprl_child_groupName)
        TextView srckApprlChildGroupName;
//        @Bind(R.id.srck_apprl_child_apprl_procId)
//        TextView srckApprlChildApprlprocId;
        @Bind(R.id.srck_apprl_child_apprl_procName)
        TextView srckApprlChildApprlChildprocName;
        @Bind(R.id.srck_apprl_child_amount)
        TextView srckApprlChildAmount;
        @Bind(R.id.srck_apprl_child_goodNum)
        TextView srckApprlChildGoodNum;
        @Bind(R.id.srck_apprl_child_pjctReq)
        TextView srckApprlChildPjctReq;
        @Bind(R.id.srck_apprl_child_otherState)
        TextView srckApprlChildOtherState;
        @Bind(R.id.lineitem)
        LinearLayout lineitem;
        @Bind(R.id.a_card)
        CardView aCard;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
